'use strict';
const getValue = function(target, paramName) {
  if (target && typeof target === 'object' && target.hasOwnProperty(paramName)) {
    return target[paramName];
  }
  if (typeof target === 'string') {
    return;
  }
  if (typeof target === 'object') {
    const keys = Object.keys(target);
    for (const key of keys) {
      const tempResult = getValue(target[key], paramName);
      if (tempResult) {
        return tempResult;
      }
    }
  }
};
const getCookieValue = function(cookies, key, paramName) {
  const cookieStr = cookies.get(key, {
    signed: true, // 对cookie进行签名 防止用户修改cookie
    encrypt: true, // 是否对cookie进行加密 如果cookie加密那么获取的时候要对cookie进行解密,这里要注意配置文件里的cookie.key和授权中心的key保持一致
  });
  if (cookieStr) {
    const cookieObj = JSON.parse(cookieStr);
    return getValue(cookieObj, paramName);
  }
  return null;

};
exports.getCookieValue = getCookieValue;
exports.getValue = getValue;

